﻿using System.Collections.Generic;
using System.Linq;
namespace QntPlatform
{
    public interface ITAFun
    {
        double[] ATR(Record[] records, int period);
    }
    public class TAFun : ITAFun
    {
        public double[] ATR(Record[] records, int period=14)
        {
            var high = new List<double>(records.Length);
            var low = new List<double>(records.Length);
           var close= records.Select(p => {
               high.Add((double)p.High);
               low.Add((double)p.Low);
               return (double)p.Close;
           }).ToArray();

            var real = new double[records.Length-period] ;
            var re = TALib.Core.Atr(high.ToArray(), low.ToArray(), close, 0, records.Length-1, real, out var beg, out var nb, period);
            if (re == TALib.Core.RetCode.Success)
            {
               
                return real.Take(nb).ToArray();
            }
            return null;
        }
    }
}